<template>
  <div class="my-container">
    <!-- 已登录 -->
    <div class="header userInfo" v-if="user" >
      <div class="base">
        <div class="left">
          <van-image
                 fit="cover"
                 :src="UserInfo.photo"
                 class="avatar"
                 round
                 />
          <span class="name">{{UserInfo.name}}</span>
        </div>
        <div class="right">
           <van-button
            type="default"
            size="mini"
            round
            to="/user/profile"
           >编辑资料</van-button>
        </div>
      </div>
    <!-- //关注粉丝 -->
    <div class="data">
      <div class="data-item">
        <span>{{UserInfo.art_count}}</span>
        <span>头条</span>
      </div>
      <div class="data-item">
        <span>{{UserInfo.fans_count}}</span>
        <span>关注</span>
      </div>
      <div class="data-item">
        <span>{{UserInfo.follow_count}}</span>
        <span>粉丝</span>
      </div>
      <div class="data-item">
        <span>{{UserInfo.like_count}}</span>
        <span>获赞</span>
      </div>
    </div>
    </div>
    <!-- 未登录 -->
    <div class="header not-login" v-else>
      <img
        class="mobile-img"
        src="~@/assets/mobile.png"
        @click="$router.push('/login')"
      >
      <span class="text">登录 / 注册</span>
    </div>

    <!-- 公共部分 -->
    <div>
      <!-- 导航 -->
       <van-grid class="nav-grid" clickable :column-num="2">
        <van-grid-item >
          <i slot="icon" class="toutiao toutiao-shoucang"></i>
          <span class="text" slot="text">收藏</span>
        </van-grid-item>
        <van-grid-item >
           <i slot="icon" class="toutiao toutiao-lishi"></i>
          <span class="text" slot="text">历史</span>
        </van-grid-item>

      </van-grid>
      <div >
        <van-cell is-link title="消息通知"  />
        <van-cell is-link title="小智同学"  />
        <van-cell v-if="user" class="logout-cell"  title="退出登录" center
        clickable
        @click="onlogout"/>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getUserInfo } from '@/api/user'
export default {
  name: 'MyIndex',
  components: {},
  props: {},
  data () {
    return {
      UserInfo: {}
    }
  },
  computed: {
    ...mapState(['user'])
  },
  watch: {},
  created () {
    if (this.user) {
      this.locaUserInfo()
    }
  },
  mounted () {},
  methods: {
    async locaUserInfo () {
      try {
        const { data } = await getUserInfo()
        // console.log(data)
        this.UserInfo = data.data
      } catch (err) {
        console.log(err)
        this.$toast('获取失败')
      }
    },
    onlogout () {
      this.$dialog.confirm({
        title: '确认退出吗'
      })
        .then(() => {
          // 点击确认，清空user值
          this.$store.commit('setUser', null)
        })
        .catch(() => {
          console.log('取消')
        })
    }
  }
}
</script>

<style scoped lang="less">
.my-container {
  > .header {
    height: 361px;
    background: url("~@/assets/banner.png") no-repeat;
    background-size: cover;
  }
  .not-login{
       display: flex;
       align-items: center;
       justify-content: center;
       flex-direction: column;
        .mobile-img {
          width: 132px;
          height: 132px;
          margin-bottom: 20px;
        }
        .text{
          font-size: 30px;
        }
    }
  .userInfo{
    .base{
      height: 231px;
      padding: 76px 32px 23px;
      //background: #ccc;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-sizing: border-box;
       .left {
        display: flex;
        align-items: center;
        .avatar {
          width: 132px;
          height: 132px;
          border: 2px solid #fff;
        }
        .name {
          font-size: 29px;
          margin-left: 22px;
        }
      }
    }
    .data {
      display: flex;
      justify-content: space-around;
      .data-item {
        height: 130px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        color: #fff;
        span:nth-child(1) {
          font-size: 36px;
          margin-bottom: 15px;
        }
        span:nth-child(2) {
          font-size: 23px;
        }
      }
    }
  }
   .nav-grid {
      background: #fff;
      .toutiao {
        font-size: 45px;
      }
      .toutiao-shoucang {
        color: #EB5253;
      }
      .toutiao-lishi {
        color: #FF9D1D;
      }
      .text {
        color: #000;
        margin-top: 8px;
        font-size: 28px;
      }
    }
    .logout-cell {
      height: 100px;
      text-align: center;
      color: #EB5253;
      margin: 10px 0;
      font-size: 30px;
    }
}
</style>
